import { request } from "./request.js";

//查询角色列表
export function getRoleList() {
  return request({
    method: "get",
    url: "/role"
  });
}
//获得单个角色信息
export function getRoleInfo(id) {
  return request({
    method: "get",
    url: `/role/${id}`
  });
}
//添加角色
export function addRole(roleInfo) {
  return request({
    method: "post",
    url: "/role",
    data: roleInfo
  });
}
//修改角色
export function putRoleInfo(roleInfo) {
  return request({
    method: "put",
    url: "/role",
    data: roleInfo
  });
}
//删除角色
export function deleteRoleById(id) {
  return request({
    method: "delete",
    url: `/role/${id}`
  });
}
//删除角色绑定的权限
export function removePermissionById(roleId, permissionId) {
  return request({
    method: "delete",
    url: `/role/${roleId}/permission/${permissionId}`
    //data:{}
  });
}

//设置用角色权限
export function setRolePermissions(roleId, idStr) {
  // axios默认对请求体序列化,后端拿不到string类型的参数, 需要用对象接收
  //通过URLSearchParams可以使请求Content-type变成"application/x-www-form-urlencoded",后端可以在Request.Form
  const params = new URLSearchParams();
  params.append("ids", idStr);
  return request({
    method: "post",
    url: `/role/${roleId}/permission`,
    data: params
  });
}
